import Data.List
import Data.Array
import Data.Ord
import Data.Char

primes :: [Integer]
primes = 2 : filter ( (==1) . length . primeFactors ) [3,5..]

primeFactors :: Integer -> [Integer]
primeFactors n = factor n primes
	where
	factor n (p:ps)
		| p*p > n		 = [n]
		| n `mod` p == 0 = p : factor ( n `div` p )	(p:ps)
		| otherwise		 = factor n ps

quadratic :: (Integer,Integer) -> Integer -> Integer
quadratic (a,b) n = n*n + a*n + b

isPrime :: Integer -> Bool
isPrime n
	| n <= 1 	= False
	| otherwise =((length(primeFactors n)) == 1)

rotations xs = map (takeSame xs) $ takeSame xs (tails (xs ++ xs)) where
    takeSame [] _ = [] 
    takeSame (_:xs) (y:ys) = y:takeSame xs ys
	
euler_035 :: Int
euler_035 = length $ filter (\x->(foldr (&&) True ( map (isPrime.read) (rotations x) ))) (map show (takeWhile (<1000000) primes))
